import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/home/index.vue'
// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push (location) {
//   return originalPush.call(this, location).catch((err) => err)
// }

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/kind',
    name: 'kind',
    component: () => import('@/views/kind/index.vue')
  },
  {
    path: '/cart',
    name: 'cart',
    component: () => import('@/views/cart/index.vue')
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('@/views/user/index.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/register',
    name: 'register',
    redirect: '/register/register1',
    component: () => import('@/views/register/index.vue'),
    meta: {
      hidden: true
    },
    children: [
      {
        path: 'register1',
        name: 'register1',
        component: () => import('@/views/register/stamp1.vue'),
        meta: {
          hidden: true
        }
      },
      {
        path: 'register2',
        name: 'register2',
        component: () => import('@/views/register/stamp2.vue'),
        meta: {
          hidden: true
        }
      },
      {
        path: 'register3',
        name: 'register3',
        component: () => import('@/views/register/stamp3.vue'),
        meta: {
          hidden: true
        }
      }
    ]
  },
  {
    path: '/detail/:proid', // 动态路由
    name: 'detail', // 命名路由
    component: () => import('@/views/detail/index.vue'), // 路由懒加载
    meta: { // 路由元信息
      hidden: true // 隐藏底部的导航
    }
  },
  {
    path: '/order/:time',
    name: 'order',
    component: () => import('@/views/order/index.vue')
  },
  {
    path: '/addresslist/:time',
    name: 'addresslist',
    component: () => import('@/views/address/index.vue')
  },
  {
    path: '/addaddress/:time',
    name: 'addaddress',
    component: () => import('@/views/addaddress/index.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/editaddress/:time',
    name: 'editaddress',
    component: () => import('@/views/editaddress/index.vue'),
    meta: {
      hidden: true
    }
  },
  {
    path: '/list', // 动态路由
    name: 'list', // 命名路由
    component: () => import('@/views/list/index.vue'), // 路由懒加载
    meta: { // 路由元信息
      hidden: true // 隐藏底部的导航
    }
  },
  {
    path: '*',
    component: () => import('@/views/error/index.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: routes
})

export default router
